package com.linkage.jz.bankruptcy.bean;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 */
public class MyAddr implements Serializable {

    public String id;
    public String province;
    public String city;
    public String region;
    public String address;
    public int provinceIndex = 0, cityIndex = 0, regionIndex = 0;
    public String zipCode;
    public boolean defaut;
    public String userName;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getZipCode() {
        return zipCode;
    }

    public void setZipCode(String zipCode) {
        this.zipCode = zipCode;
    }

    public boolean isDefaut() {
        return defaut;
    }

    public void setDefaut(boolean defaut) {
        this.defaut = defaut;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getFullAddress() {
        return city + region + address;
    }

    public int getProvinceIndex() {
        return provinceIndex;
    }

    public void setProvinceIndex(int provinceIndex) {
        this.provinceIndex = provinceIndex;
    }

    public int getCityIndex() {
        return cityIndex;
    }

    public void setCityIndex(int cityIndex) {
        this.cityIndex = cityIndex;
    }

    public int getRegionIndex() {
        return regionIndex;
    }

    public void setRegionIndex(int regionIndex) {
        this.regionIndex = regionIndex;
    }

    public static List<MyAddr> parse(JsonArray arr) {
        List<MyAddr> list = new ArrayList<>();
        for (int i = 0; i < arr.size(); i++) {
            list.add(parse(arr.get(i).getAsJsonObject()));
        }
        return list;
    }

    public static MyAddr parse(JsonObject obj) {
        MyAddr bean = new Gson().fromJson(obj, MyAddr.class);
        return bean;
    }

    public MyAddr toMyArr(AddressInfo mAddrInfo)
    {
        MyAddr addr = new MyAddr();
        addr.id = mAddrInfo.getId();
        addr.province = mAddrInfo.getProvince();
        addr.city = mAddrInfo.getCity();
        addr.address = mAddrInfo.getAddress();
        addr.region = mAddrInfo.getRegion();
        addr.zipCode = mAddrInfo.getZipCode();
        return addr;
    }

    public AddressInfo toArrInfo(MyAddr mAddrInfo)
    {
        AddressInfo addr = new AddressInfo();
        addr.id = mAddrInfo.getId();
        addr.province = mAddrInfo.getProvince();
        addr.city = mAddrInfo.getCity();
        addr.address = mAddrInfo.getAddress();
        addr.region = mAddrInfo.getRegion();
        addr.zipCode = mAddrInfo.getZipCode();
        return addr;
    }
}